package com.holyn.guofang.zxing.utils;

import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Abe on 2016/10/4.
 */
public  class ToJSonObject {

    public  static JSONObject beanToJSONObejct(Object json){
        Gson g=new Gson();
        String Json =g.toJson(json);
        JSONObject myJsonObject = null;
        try {
            myJsonObject = new JSONObject(Json);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return myJsonObject ;
    }
    //json对象 to java对象
    public static <T> T jsonToBean(String jsonString, Class<T> cls) {
        T t = null;
        try {
            Gson gson = new Gson();
            t = gson.fromJson(jsonString, cls);
        } catch (Exception e) {
        }
        return t;
    }

    public static String getFileName(String pathandname) {
        int start = pathandname.lastIndexOf("/");
        int end = pathandname.length();
        if (start != -1 && end != -1) {
            return pathandname.substring(start + 1, end);
        } else {
            return null;
        }
    }
}
